package com.amumu.drama.common.modules.category.mapping;

import com.amumu.drama.common.base.mapstruct.BaseMapping;
import com.amumu.drama.common.modules.fulu.dto.resp.FuluProductResp;
import com.amumu.drama.model.PmsSkuStock;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import java.util.Objects;

/**
 * @author sunzhuang
 * @date 2024/9/11 16:19
 * @slogan 天下风云出我辈, 一入代码岁月催
 * @desc todo
 */
@Mapper(componentModel = "spring")
public interface PmsSkuStockMapping extends BaseMapping<FuluProductResp, PmsSkuStock> {

    PmsSkuStockMapping INSTANCE = Mappers.getMapper(PmsSkuStockMapping.class);

    /**
     * 正向映射的后置处理，List映射会自动继承此配置
     *
     * @param src
     * @param dest
     */
    @Override
    default void afterConvertTo(FuluProductResp src, PmsSkuStock dest) {
        dest.setDirectTemplateId(src.getTemplateId());
        dest.setDirectPublishStatus(Objects.equals("上架", src.getSalesStatus()) ? 1 : 0);
        dest.setDirectSkuName(src.getProductName());
        dest.setDirectStockStatus(Objects.equals("充足", src.getStockStatus()) ? 1 : 0);
        dest.setPublishStatus(Objects.equals(dest.getDirectPublishStatus(), 0) ? 0 : null);
        dest.setPrice(src.getFaceValue());
        dest.setCostPrice(src.getPurchasePrice());
        dest.setSkuCode(src.getProductId().toString());
    }
}
